var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("GlobalUserData"),
s = t("GameConstant"),
l = t("Util"),
c = t("Global"),
d = t("GamePKScene"),
h = t("GameBoutOverView"),
p = t("GamePKOverView"),
u = cc._decorator,
f = u.ccclass,
m = u.property,
_ = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.pfb_gameOver = null,
        e.pfb_boutOver = null,
        e.prog_hpLeft = null,
        e.node_hpLeft = null,
        e.lab_hpLeft = null,
        e.lab_damageLeft = null,
        e.icon_winLeft = new Array(3),
        e.sprite_leftHead = null,
        e.prog_hpRight = null,
        e.node_hpRight = null,
        e.lab_hpRight = null,
        e.lab_damageRight = null,
        e.icon_winRight = new Array(3),
        e.sprite_rightHead = null,
        e.frame_player = null,
        e.node_btn = new Array,
        e.node_content = null,
        e._gameControl = null,
        e.maxHpLeft = 0,
        e.maxHpRight = 0,
        e.curHpLeft = 0,
        e.curHpRight = 0,
        e.curDamageLeft = 0,
        e.curDamageRight = 0,
        e.isHpLeftAnim = !1,
        e.isHpRightAnim = !1,
        e.isGameOver = !1,
        e._GamePKOverView = null,
        e
    }
    return n(e, t),
    e.prototype.update = function() {
        this.isHpLeftAnim && (this.node_hpLeft.width = this.node_hpLeft.width - 2, this.node_hpLeft.width < 0 && (this.node_hpLeft.width = 0), this.node_hpLeft.width <= this.prog_hpLeft.totalLength * this.prog_hpLeft.progress && (this.isHpLeftAnim = !1)),
        this.isHpRightAnim && (this.node_hpRight.width = this.node_hpRight.width - 2, this.node_hpRight.width < 0 && (this.node_hpRight.width = 0), this.node_hpRight.width <= this.prog_hpRight.totalLength * this.prog_hpRight.progress && (this.isHpRightAnim = !1))
    },
    e.prototype.initView = function() {
        this._gameControl = this.node.getComponent(d.default);
        for (var t = 0; t < this.icon_winLeft.length; t++) this.icon_winLeft[t].active = !1;
        for (t = 0; t < this.icon_winRight.length; t++) this.icon_winRight[t].active = !1;
        for (t = 0; t < this.node_btn.length; t++) this.node_btn[t].zIndex = s.Scene_Z_Index.Btn;
        if (this.resetView(), !this._GamePKOverView) {
            var e = cc.instantiate(this.pfb_gameOver);
            this.node_content.addChild(e, s.Scene_Z_Index.Over),
            this._GamePKOverView = e.getComponent(p.default)
        }
        this._GamePKOverView.init(this._gameControl, this._gameControl.rEquipBodyData, this._gameControl.rEquipWheelData, this._gameControl.rEquipWeaponData, this._gameControl.rEquipToolsData)
    },
    e.prototype.resetView = function() {
        this.lab_hpLeft.string = this.maxHpLeft.toString(),
        this.lab_hpRight.string = this.maxHpRight.toString(),
        this.lab_damageLeft.string = this.curDamageLeft.toString(),
        this.lab_damageRight.string = this.curDamageRight.toString(),
        this.prog_hpLeft.progress = this.curHpLeft / this.maxHpLeft,
        this.prog_hpRight.progress = this.curHpRight / this.maxHpRight,
        this.node_hpLeft.width = this.prog_hpLeft.totalLength * this.prog_hpLeft.progress,
        this.node_hpRight.width = this.prog_hpRight.totalLength * this.prog_hpRight.progress,
        this.isHpLeftAnim = !1,
        this.isHpRightAnim = !1
    },
    e.prototype.onRestartGame = function() {
        this.frame_player.active = !0;
        for (var t = 0; t < this.node_btn.length; t++) this.node_btn[t].active = !0
    },
    e.prototype.onGameStart = function() {
        this._GamePKOverView.onGameStart()
    },
    e.prototype.onGameOver = function(t, e) {
        this.isGameOver = !0,
        this._GamePKOverView.onGameOver(t, e),
        this.frame_player.active = !1;
        for (var o = 0; o < this.node_btn.length; o++) this.node_btn[o].active = !1
    },
    e.prototype.onGameBoutStart = function() {
        this.isGameOver = !1
    },
    e.prototype.onGameBoutOver = function() {
        this.isGameOver = !0
    },
    e.prototype.onGameWin = function() {
        this._GamePKOverView.onGameWin()
    },
    e.prototype.onGameFail = function() {
        this._GamePKOverView.onGameFail()
    },
    e.prototype.onGameBoutWin = function() {
        var t = this;
        this.onShowBoutOver(!0, this._gameControl.nLeftWinBount),
        this.node_hpLeft.stopAllActions(),
        cc.tween(this.node_hpLeft).delay(1.5).call(function() {
            t._gameControl.playAudio(s.Game_Audio_ID.result_victory)
        }).start(),
        this._gameControl.onGameBoutWin()
    },
    e.prototype.onGameBoutFail = function() {
        var t = this;
        this.onShowBoutOver(!1, this._gameControl.nRightWinBount),
        this.scheduleOnce(function() {
            t._gameControl.playAudio(s.Game_Audio_ID.result_defeat)
        },
        1.5),
        this.node_hpLeft.stopAllActions(),
        cc.tween(this.node_hpLeft).delay(1.5).call(function() {
            t._gameControl.playAudio(s.Game_Audio_ID.result_defeat)
        }).start(),
        this._gameControl.onGameBoutFail()
    },
    e.prototype.onShowBoutOver = function(t, e) {
        var o = cc.instantiate(this.pfb_boutOver);
        this.node_content.addChild(o, s.Scene_Z_Index.BoutOver),
        o.getComponent(h.default).showAnim(this, t, e)
    },
    e.prototype.onShowWinStar = function(t, e) {
        var o = function(t) {
            cc.tween(t).to(.2, {
                scale: 1.5
            }).to(.3, {
                scale: .8
            }).to(.1, {
                scale: 1
            }).start()
        };
        t ? (this.icon_winLeft[e].active = !0, o(this.icon_winLeft[e])) : (this.icon_winRight[e].active = !0, o(this.icon_winRight[e]))
    },
    e.prototype.getStarPos = function(t, e) {
        if (t) {
            var o = this.icon_winLeft[e].convertToWorldSpaceAR(cc.Vec2.ZERO);
            return this.node.convertToNodeSpaceAR(o)
        }
        return o = this.icon_winRight[e].convertToWorldSpaceAR(cc.Vec2.ZERO),
        this.node.convertToNodeSpaceAR(o)
    },
    e.prototype.damageHpLeft = function(t, e) {
        if (!this.isGameOver && r.default.skillType != c.Props.Invincible) {
            t = r.default.propType == c.Props.Bubble ? .5 * t: t;
            var o = r.default.propType == c.Props.Bubble ? 3 * this.maxHpLeft / 10 * .5 : 3 * this.maxHpLeft / 10;
            this.curHpLeft -= e ? o: t,
            this.curHpLeft <= 0 && (this.curHpLeft = 0, this.onGameBoutFail()),
            this.prog_hpLeft.progress = this.curHpLeft / this.maxHpLeft,
            this.node_hpLeft.width > 0 && (this.isHpLeftAnim = !0)
        }
    },
    e.prototype.damageHpRight = function(t, e) {
        this.isGameOver || (this.curHpRight -= e ? 3 * this.maxHpRight / 10 : t, this.curHpRight <= 0 && (this.curHpRight = 0, this.onGameBoutWin()), this.prog_hpRight.progress = this.curHpRight / this.maxHpRight, this.node_hpRight.width > 0 && (this.isHpRightAnim = !0))
    },
    e.prototype.onPlaneBombDamage = function(t) {
        this.isGameOver || (this.curHpRight -= this.maxHpRight * t, this.curHpRight <= 0 && (this.curHpRight = 0, this.onGameBoutWin()), this.prog_hpRight.progress = this.curHpRight / this.maxHpRight, this.node_hpRight.width > 0 && (this.isHpRightAnim = !0))
    },
    e.prototype.initLeftData = function(t, e, o, i, n) {
        for (var a = l.Util.getBodyData(t), s = l.Util.transformHpNum(a.hp, a.level), c = 0, d = 0; d < e.length; d++) if (e[d]) {
            var h = l.Util.getWeaponData(e[d]);
            c += l.Util.transformDamageNum(h.damage, h.level)
        }
        for (d = 0; d < o.length; d++) if (o[d]) {
            var p = l.Util.getWheelData(o[d]);
            s += l.Util.transformHpNum(p.hp, p.level)
        }
        for (d = 0; d < i.length; d++) if (i[d]) {
            var u = l.Util.getToolsData(i[d]);
            s += l.Util.transformHpNum(u.hp, u.level)
        }
        this.curHpLeft = n || s,
        this.maxHpLeft = s,
        (this.curHpLeft > this.maxHpLeft || r.default.isTryCar) && (this.curHpLeft = this.maxHpLeft),
        this.curDamageLeft = c
    },
    e.prototype.initRightView = function(t, e) {
        this.sprite_rightHead.spriteFrame = e,
        this._GamePKOverView.initRightView(t, e)
    },
    e.prototype.initRightData = function(t, e, o, i, n) {
        for (var a = t.hp,
        r = 0,
        s = 0; s < o.length; s++) o[s] && (r += o[s].damage);
        for (s = 0; s < e.length; s++) e[s] && (a += e[s].hp);
        for (s = 0; s < i.length; s++) i[s] && (a += i[s].hp);
        this.curHpRight = n || a,
        this.maxHpRight = a,
        this.curHpRight > this.maxHpRight && (this.curHpRight = this.maxHpRight),
        this.curDamageRight = r
    },
    a([m(cc.Prefab)], e.prototype, "pfb_gameOver", void 0),
    a([m(cc.Prefab)], e.prototype, "pfb_boutOver", void 0),
    a([m(cc.ProgressBar)], e.prototype, "prog_hpLeft", void 0),
    a([m(cc.Node)], e.prototype, "node_hpLeft", void 0),
    a([m(cc.Label)], e.prototype, "lab_hpLeft", void 0),
    a([m(cc.Label)], e.prototype, "lab_damageLeft", void 0),
    a([m(cc.Node)], e.prototype, "icon_winLeft", void 0),
    a([m(cc.Sprite)], e.prototype, "sprite_leftHead", void 0),
    a([m(cc.ProgressBar)], e.prototype, "prog_hpRight", void 0),
    a([m(cc.Node)], e.prototype, "node_hpRight", void 0),
    a([m(cc.Label)], e.prototype, "lab_hpRight", void 0),
    a([m(cc.Label)], e.prototype, "lab_damageRight", void 0),
    a([m(cc.Node)], e.prototype, "icon_winRight", void 0),
    a([m(cc.Sprite)], e.prototype, "sprite_rightHead", void 0),
    a([m(cc.Node)], e.prototype, "frame_player", void 0),
    a([m(cc.Node)], e.prototype, "node_btn", void 0),
    a([m(cc.Node)], e.prototype, "node_content", void 0),
    a([f], e)
} (cc.Component);
o.default = _